package cn.haohaowo.webservice.client;

import org.apache.cxf.endpoint.Client;
import org.apache.cxf.interceptor.LoggingInInterceptor;
import org.apache.cxf.interceptor.LoggingOutInterceptor;
import org.apache.cxf.jaxws.JaxWsClientFactoryBean;
import org.apache.cxf.jaxws.JaxWsProxyFactoryBean;

import cn.haohaowo.webservice.HelloWorldService;

public class WebServiceClient {

	/**
	 * @param args
	 */
	public static void main(String[] args) throws Exception {
		JaxWsProxyFactoryBean jaxWsProxyFactoryBean = new JaxWsProxyFactoryBean();
		jaxWsProxyFactoryBean.getInInterceptors().add(new LoggingInInterceptor());
		jaxWsProxyFactoryBean.getInFaultInterceptors().add(new LoggingOutInterceptor());
		jaxWsProxyFactoryBean.setServiceClass(HelloWorldService.class);
		
		jaxWsProxyFactoryBean.setAddress("http://localhost:9999/Apache-CXF/webservice/helloWorldService");
		HelloWorldService helloWorldService = (HelloWorldService) jaxWsProxyFactoryBean.create();
		String result = helloWorldService.sayHello("Robinson");
		System.out.println(result);
		
		JaxWsClientFactoryBean jaxWsClientFactoryBean = new JaxWsClientFactoryBean();
		jaxWsClientFactoryBean.getInInterceptors().add(new LoggingInInterceptor());
		jaxWsClientFactoryBean.getInFaultInterceptors().add(new LoggingOutInterceptor());
		jaxWsClientFactoryBean.setServiceClass(HelloWorldService.class);
		jaxWsClientFactoryBean.setAddress("http://localhost:9999/Apache-CXF/webservice/helloWorldService");
		Client client = jaxWsClientFactoryBean.create();
		Object[] obj = client.invoke("sayHello", "Robinson");
		System.out.println(obj[0]);
	}

}
